package com.yangjun.controller.common;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Maps;
import com.yangjun.service.common.CommonService;
import com.yangjun.utils.AjaxJson;

@RestController
@RequestMapping("/common")
public class CommonController {
	@Autowired
	private CommonService commonService;

	/**
	 * http://192.168.7.32:8080/common/getSalesPlatform
	 * 
	 * @param response
	 * @return
	 */
	@RequestMapping("/getSalesPlatform")
	@ResponseBody
	public AjaxJson getSalesPlatform(HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AjaxJson j = new AjaxJson();
		j.setAttributes(commonService.getSalesPlatform());
		return j;
	}

	/**
	 * http://192.168.7.32:8080/common/getSaleManagerPlatform?loginname=hjd2424891
	 * @param response
	 * @param loginname
	 * @return
	 */
	@RequestMapping("/getSaleManagerPlatform")
	@ResponseBody
	public AjaxJson getSaleManagerPlatform(HttpServletResponse response,
			@RequestParam(value = "loginname", required = true) String loginname) {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		AjaxJson j = new AjaxJson();
		j.setAttributes(commonService.getSaleManagerPlatform(loginname));
		return j;
	}
	
	
	/**
	 * http://192.168.7.32:8080/common/getShopOfOrdersource?ordersource=53
	 * @param ordersource
	 * @param response
	 * @return
	 */
	@RequestMapping("/getShopOfOrdersource")
	@ResponseBody
	public AjaxJson getShopOfOrdersource(
			@RequestParam(value = "ordersource",required = true)String ordersource,
			HttpServletResponse response){
		 AjaxJson j = new AjaxJson();
		 Map<String, Object> parameter = Maps.newHashMap();
		 parameter.put("ordersource", ordersource);
		 Map<String, Object> attributes = Maps.newHashMap();
	     attributes.put("shop", commonService.getShopOfOrdersource(parameter));
		 j.setAttributes(attributes);
		 return j;
	}

}
